/*
 *  SSCatalystDocumentData.h
 *  MESLib
 * 
 * Copyright 2003-2009 Starline Software Ltd
 * 
 * This file is part of MESLib.
 * 
 * MESLib is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * MESLib is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with MESLib. If not, see <http://www.gnu.org/licenses/>.
 */
//  Created by Tobias Haughton on Sat Jan 25 2003.
//

#import <Foundation/Foundation.h>
#import "SSEventObject.h"
#import "SSEventLinkObject.h"
#import "NSArray_Extensions.h"
#import "SSCatalystComment.h"
#import "SSNeedsDiamond.h"
#import "SSEBDuplicateEditPanelController.h"
#import "SSImportDuplicateAlertController.h"
#import "SSDiamondOption.h"
#import "SSDiamondTradeoff.h"
#import "SSPoisonWord.h"

@class SSCatalystDocument;

@interface SSCatalystDocumentData : NSObject<NSCoding> {
   NSMutableDictionary *structureDictionary; //holds the structure of this chart as setup in the file directory

   NSMutableDictionary *aalosDictionary; //holds four dictionaries
                                         //actions
                                         //actors
                                         //locations
                                         //objects
                                         //sources
                                         //remark
                                         //each of these holds an array of event unique_id's for each unique action, actor, location and event
   NSMutableDictionary *dataSourceDictionary; //holds four arrays
                                         //action
                                         //actor
                                         //location
                                         //object
                                         //source
                                         //remark
                                         //each of these holds a string for each unique value
                                         //this is used to populate the table and comboBox
   NSMutableDictionary *alphabeticDataSourceDictionary; //mirrors dataSourceDictionary but is sorted alphabetically

   NSMutableDictionary *defaultNeedsDiamondValues; //holds the default values for analyst and fileID
                                    
   NSMutableArray *eventArray;
   NSMutableArray *commentArray;
   NSMutableArray *needsDiamondArray;
   NSMutableArray *filteredActorArray;
   SSCatalystDocument *theDocument;
   float actorColumnWidth;
   int displayMode;
   float overlapUnit;
   float overlapPixelsPerUnit;
   SSEventObject *currentLinkFromEvent;
   BOOL importCanceled;
}

- (id)initWithDocument:(SSCatalystDocument *)document;

- (NSMutableArray *)eventArray;
- (NSMutableArray *)allEventsInStructure:(NSMutableDictionary *)dict;
- (NSMutableArray *)commentArray;
- (NSMutableArray *)allCommentsInStructure:(NSMutableDictionary *)dict;
- (NSMutableArray *)needsDiamondArray;
- (NSMutableDictionary *)aalosDictionary;
- (NSMutableDictionary *)structureDictionary;

- (void)setAalosDictionary:(NSMutableDictionary *)dict;
- (void)setDataSourceDictionary:(NSMutableDictionary *)dict;
- (void)setStructureDictionary:(NSMutableDictionary *)dict;
- (void)removeAllTracesOfStructureDict:(NSMutableDictionary *)dict;
- (void)setTheDocument:(id)doc;

- (void)setEventArray:(NSMutableArray *)array;
- (void)setCommentArray:(NSMutableArray *)array;
- (void)setNeedsDiamondArray:(NSMutableArray *)array;

- (void)addEventToDocument:(SSEventObject *)event structureDictionary:(NSMutableDictionary *)dict;
- (void)addEventsFromArray:(NSMutableArray *)array;
- (void)removeEventFromDocument:(SSEventObject *)event;
- (void)addEventToAalosDictionary:(SSEventObject *)event;
- (void)addEventToAalosDictionary:(SSEventObject *)event forKey:(NSString *)key;
- (void)aalosDictionaryRemoveEvent:(SSEventObject *)event fromDictWithKey:(NSString *)key;
- (NSString *)aalosDictionaryKeyForEventWithUniqueId:(NSString *)unique inDictForKey:(NSString *)key;
- (void)aalosDictionaryChangeActorEntry:(NSNotification *)note;
- (void)aalosDictionaryChangeActionEntry:(NSNotification *)note;
- (void)aalosDictionaryChangeLocationEntry:(NSNotification *)note;
- (void)aalosDictionaryChangeSourceEntry:(NSNotification *)note;
- (void)aalosDictionaryChangeObjectEntry:(NSNotification *)note;

- (NSString *)dataSourceDictionaryArrayWithKey:(NSString *)key objectAtIndex:(int)index;
- (NSString *)alphabeticDataSourceDictionaryArrayWithKey:(NSString *)key objectAtIndex:(int)index;
- (void)dataSourceDictionaryArrayWithKey:(NSString *)key removeString:(NSString *)string;
- (int)dataSourceDictionaryIndexOfObject:(NSString *)object inArray:(NSString *)arrayName;
- (void)dataSourceDictionaryArrayWithKey:(NSString *)key moveObjectsAtIndexes:(NSArray *)movingIndexes toIndex:(int)index;
- (void)dataSourceDictionaryArrayWithKey:(NSString *)key addString:(NSString *)string;

- (void)orderActorsBasedOnArray:(NSMutableArray *)orderArray;
- (void)orderActorsForImportedFileBasedOnArray:(NSMutableArray *)orderArray;

- (NSMutableDictionary *)structureDictionaryForObject:(id)object;
- (NSMutableDictionary *)structureDictionaryForObject:(id)object key:(NSString *)key dictionary:(NSMutableDictionary *)dict;
- (id)structureObjectForKey:(NSString *)key;

- (void)addCommentToDocument:(SSCatalystComment *)comment structureDictionary:(NSMutableDictionary *)dict;
- (void)removeCommentFromDocument:(SSCatalystComment *)comment;
- (void)addCommentsFromArray:(NSMutableArray *)array;

- (void)addNeedsDiamondToDocument:(SSNeedsDiamond *)diamond structureDictionary:(NSMutableDictionary *)dict;
- (void)addNeedsDiamondsFromArray:(NSMutableArray *)array;
- (void)removeNeedsDiamondFromDocument:(SSNeedsDiamond *)diamond;
- (void)renumberNeedsDiamondsAboveIndex:(int)index;
- (void)setDefaultNeedsDiamondValuesDict:(NSMutableDictionary *)dict;
- (void)setDefaultNeedsDiamondValue:(NSString *)value forKey:(NSString *)key;
- (NSString *)defaultNeedsDiamondValueForKey:(NSString *)key;

- (int)numberOfUniqueLocations;
- (int)numberOfUniqueActions;
- (int)numberOfUniqueActors;
- (int)numberOfUniqueObjects;
- (int)numberOfUniqueSources;
- (int)numberOfUniqueRemarks;
- (int)numberOfActorsWithName:(NSString *)theName;

- (NSString *)title;
- (void)setTitle:(NSString *)string;
- (NSString *)author;
- (void)setAuthor:(NSString *)string;
- (NSCalendarDate *)chartDate;
- (void)setChartDate:(NSCalendarDate *)date;
- (NSString *)whiteColorDesignation;
- (void)setWhiteColorDesignation:(NSString *)string;
- (NSString *)yellowColorDesignation;
- (void)setYellowColorDesignation:(NSString *)string;
- (NSString *)greenColorDesignation;
- (void)setGreenColorDesignation:(NSString *)string;
- (NSString *)lightBlueColorDesignation;
- (void)setLightBlueColorDesignation:(NSString *)string;
- (NSString *)blueColorDesignation;
- (void)setBlueColorDesignation:(NSString *)string;
- (NSString *)purpleColorDesignation;
- (void)setPurpleColorDesignation:(NSString *)string;
- (NSString *)orangeColorDesignation;
- (void)setOrangeColorDesignation:(NSString *)string;
- (NSString *)redColorDesignation;
- (void)setRedColorDesignation:(NSString *)string;
- (void)setProjectFolder:(NSString *)path;
- (NSString *)projectFolder;

- (NSString *)diamondUDValue1;
- (void)setDiamondUDValue1:(NSString *)string;
- (NSString *)diamondUDValue2;
- (void)setDiamondUDValue2:(NSString *)string;
- (NSString *)diamondUDValue3;
- (void)setDiamondUDValue3:(NSString *)string;
- (NSString *)diamondUDValue4;
- (void)setDiamondUDValue4:(NSString *)string;
- (NSString *)diamondUDValue5;
- (void)setDiamondUDValue5:(NSString *)string;
- (NSString *)diamondUDValue6;
- (void)setDiamondUDValue6:(NSString *)string;
- (NSString *)diamondOptionUDValue1;
- (void)setDiamondOptionUDValue1:(NSString *)string;
- (NSString *)diamondOptionUDValue2;
- (void)setDiamondOptionUDValue2:(NSString *)string;
- (NSString *)diamondOptionUDValue3;
- (void)setDiamondOptionUDValue3:(NSString *)string;
- (NSString *)diamondOptionUDValue4;
- (void)setDiamondOptionUDValue4:(NSString *)string;
- (NSString *)diamondOptionUDValue5;
- (void)setDiamondOptionUDValue5:(NSString *)string;
- (NSString *)diamondTradeoffUDValue1;
- (void)setDiamondTradeoffUDValue1:(NSString *)string;
- (NSString *)diamondTradeoffUDValue2;
- (void)setDiamondTradeoffUDValue2:(NSString *)string;
- (NSString *)diamondTradeoffUDValue3;
- (void)setDiamondTradeoffUDValue3:(NSString *)string;

- (void)createGhostEventWithAddress:(NSString *)address;

- (void)convertAllLinksToConnectionObjects;
- (void)convertLinksForEventsInDictionary:(NSMutableDictionary *)structDict appendToFrontOfLink:(NSString *)appentToFront;
- (void)convertLinksForEvent:(SSEventObject *)eventObject;
- (void)convertAllDiamondOwners;
- (void)convertAllDiamondOwnersInDictionary:(NSMutableDictionary *)dict appendToFrontOfOwnerAddress:(NSString *)append;
- (void)convertOwnerForDiamond:(SSNeedsDiamond *)diamond appendToFrontOfOwnerAddress:(NSString *)append;

- (SSEventObject *)eventWithAddress:(NSString *)address;
- (SSEventObject *)eventWithUniqueId:(NSString *)theId;
- (BOOL)hasEventForAddress:(NSString *)address inStructureDictionary:(NSMutableDictionary *)dict;

- (NSData *)glossaryDataForType:(NSString *)type;
- (NSData *)remarkListData;
- (NSData *)eventListData;
- (NSData *)commentListData;
- (NSData *)diamondListData;
- (NSData *)optionGlossaryData;
- (NSData *)proTradeoffGlossaryData;
- (NSData *)conTradeoffGlossaryData;

- (void)validateEventBeginTime:(SSEventObject *)event;
- (void)validateNewEventBeginTime:(SSEventObject *)event;
- (BOOL)eventExistsWithActorAndTime:(SSEventObject *)event;

- (NSString *)addressForNewEvent;

- (void)setActorColumnWidth:(float)num;
- (float)actorColumnWidth;

- (BOOL)importCanceled;
- (void)setImportCanceled:(BOOL)b;

- (SSEventObject *)currentLinkFromEvent;
- (void)setCurrentLinkFromEvent:(SSEventObject *)event;

- (SSEventObject *)closestEventToComment:(SSCatalystComment *)comment;

- (void)updateFilteredActorArray;
- (NSMutableArray *)filteredActorArray;

- (int)displayMode;
- (void)setDisplayMode:(int)mode;
- (float)overlapUnit;
- (void)setOverlapUnit:(float)unit;
- (float)overlapPixelsPerUnit;
- (void)setOverlapPixelsPerUnit:(float)pix;

- (void)convertAllCommentClosestEvents;
- (void)convertAllCommentClosestEventsInDictionary:(NSMutableDictionary *)dict;
- (void)convertClosestEventForComment:(SSCatalystComment *)comment;

- (NSMutableArray *)poisonWordArray;
- (void)addPoisonWord:(SSPoisonWord *)word;
- (void)removePoisonWord:(SSPoisonWord *)word;

- (NSMutableArray *)allEventsContainingString:(NSString *)string;
- (NSMutableArray *)allEventsWithActorContainingString:(NSString *)string;
- (NSMutableArray *)allEventsWithActionContainingString:(NSString *)string;
- (NSMutableArray *)allEventsWithObjectContainingString:(NSString *)string;
- (NSMutableArray *)allEventsWithSourceContainingString:(NSString *)string;
- (NSMutableArray *)allEventsWithLocationContainingString:(NSString *)string;
- (NSMutableArray *)allEventsWithRemarkContainingString:(NSString *)string;
- (NSMutableArray *)allEventsWithBeginDate:(NSCalendarDate *)date;
- (NSMutableArray *)allEventsWithBeginTime:(NSCalendarDate *)date;
- (NSMutableArray *)allEventsWithEndDate:(NSCalendarDate *)date;
- (NSMutableArray *)allEventsWithEndTime:(NSCalendarDate *)date;
- (NSMutableArray *)allCommentsContainingString:(NSString *)string;
- (NSMutableArray *)allDiamondsContainingString:(NSString *)string;
@end
